<template>
	<view>
		<!-- 下拉框 -->
		<picker @change="xiala($event)" :value="index1" :range="list1" v-if="dat.type == 'select'" :id="dat.num">
			<view class="uni-input">{{list1[index1]}}</view>
		</picker>
		<!-- 日期 -->
		<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="riqi" v-if="dat.type == 'date'" :id="dat.num">
			<view class="uni-input">{{date}}</view>
		</picker>
		<!--文本域  -->
		<textarea v-model="textarea" v-if="dat.type == 'textarea'" placeholder="请输入"/>
	</view>
</template>

<script>
	export default {
		data() {
			// 日期
			const currentDate = this.getDate({format: true})
			return {
				// 下拉框
				index1: 0,
				index2: 0,
				index3: 0,
				index4: 0,
				index5: 0,
				list1:[],
				list2:[],
				list3:[],
				list4:[],
				list5:[],
				// 日期
				date: currentDate,
				textarea:''
			}
		},
		props:['dat'],
		// 日期
		computed: {
		        startDate() {return this.getDate('start')},
		        endDate() {return this.getDate('end')}
		},
		watch:{
			textarea:function(){
				this.$emit('textarea',{
					name:this.textarea,
					id:this.dat.item.id,
					item:this.dat.item
				})
			}
		},
		mounted() {
			console.log(this.dat.item.query07,99999)
			this.data_t(this.dat.item.query08)
			if(this.dat.item.query07 != null && this.dat.item.query07 != ''){
				this.date = this.dat.item.query07
				this.textarea = this.dat.item.query07
			}
		},
		methods: {
			// 日期
			riqi: function(e) {
				console.log(e,888)
				this.date = e.target.value
				this.$emit('w_rq',{
					name:this.date,
					id:e.target.id,
					item:this.dat.item
				})
			},
			getDate:function(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			// 下拉框
			xiala: function(e) {
				console.log(e,11111)
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.index1 = e.target.value
				this.$emit('w_xl',{
					name:this.list1[this.index1],
					id:e.target.id,
					item:this.dat.item
				})
			},
			// 数据字典
			data_t:function(type){
				console.log(type)
				console.log(this.dat.item.query07)
				this.$get('sys/dict/getDictItems/' + type).then((res)=>{
					res.data.result.forEach((item)=>{
						this.list1.push(item.title)
					})
					console.log(this.list1)
					this.list1.forEach((item,index)=>{
						if(item == this.dat.item.query07){
							this.index1 = index
						}
					})
				})
			}
		}
	}
</script>

<style>
	textarea{
		width: 100%;
		height: 300rpx;
		border: 1rpx solid rgba(230,230,230,1);
		padding: 20rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}
</style>
